<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2020/7/13
 * Time: 19:58
 */

namespace App\Services;


use App\Model\GroupModel;
use App\Model\MsgModel;
use App\Model\UserGroupModel;
use App\Model\UserModel;
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\Logger;

class GroupMsgService
{


    /**
     * 清理消息
     */
    public function clearMsg($param,$userInfo){
        try{
            $msg = MsgModel::create()->get(['msg_id'=>$param['extra']['msg_id']]);
            if(empty($msg)){
               return   ReponseCodeService::CODE_FAILE;
            }

            $where['user_id'] = $userInfo['id'];
            $where['to_id'] =  $msg['group_id'];
            if(UserGroupModel::create()->update(['last_msg_id'=>$param['extra']['msg_id'],'updated_at'=>HelpService::msectimeToStr(HelpService::msectime())],['user_id'=>$userInfo['id'],'group_id'=>$msg['group_id']])){
                return ReponseCodeService::CODE_OK;
            }
            return ReponseCodeService::CODE_FAILE;
        }catch(\Throwable $t){
            return ReponseCodeService::CODE_SERVICE_UNAVAILABLE;
        }
    }
}